/**
 * Created by Administrator on 2018-03-02.
 */

var requestMode = require('../../../js/requestsMode.js');
var constants = require('../../../js/constants.js');
var session = require('../../../js/session.js');
var Tools = require('../../../js/Tools.js');
Page({
    data:{
        list:[],
        pageTotal : '',
        page : 1,
        notShopping:'../../../images/notOrder.png',
        listLength : 0
    },
    onLoad: function () {
        let that = this;
        that.requestList(1);
    },
    requestList: function (page) {
        let that = this;
        let list = that.data.list;
        Tools.showLoaddingDefault();
        requestMode.sendRequest('member/goods-gives','POST',{size:constants.size,page:page},{sKey:session.get('sKey')}).then(function (getGiveListSuccess) {
            let code = getGiveListSuccess.data.code;
            if( code == 200 ){
                let data = getGiveListSuccess.data.data.list;
                let pageTotal = getGiveListSuccess.data.data.page_total;
                list = list.concat(data);
                that.setData({
                    list : list,
                    pageTotal : pageTotal,
                    listLength : list.length
                })
            }else{
                Tools.showErrorToast(getGiveListSuccess.data.message)
            }
            Tools.hideLoaddingToast();
        }, function () {
            Tools.hideLoaddingToast();
            Tools.showWrongNetWorkToast();
        })
    },
    onPullDownRefresh: function () {
        this.setData({
            list:[],
            pageTotal : '',
            page : 1,
            listLength : 0
        });
        this.onLoad();
    },
    onReachBottom: function () {
        let that = this;
        let currentPage  = that.data.page;
        let pageTotal = that.data.pageTotal;
        if( currentPage < pageTotal){
          that.requestList(currentPage+1)
        }
        that.setData({
            page : currentPage+1
        })
    }
});